import React, { Component } from 'react'
import { BrowserRouter as Router, Switch,Redirect,Route } from 'react-router-dom'
import { loadComponent } from '../utils' //路由懒加载方法
import Layout from '../layout'

//路由懒加载
const NotFound = loadComponent(() => import('../pages/common/notfound'))
const Login = loadComponent(() => import('../pages/login'))
const Home = loadComponent(() => import('../pages/home/home'))
const Empty = loadComponent(() => import('../pages/empty'))
const UserList = loadComponent(() => import('../pages/user'))
const UserEdit = loadComponent(() => import('../pages/user/Edit'))
const ProductVideo = loadComponent(() => import('../pages/video'))

class App extends Component {

    hasLogin() {
        return !!sessionStorage.getItem('login-Info')
    }
    render() {
        return (
            <Router>
                <Layout>
                    <Switch>
                        <Route path="/404" component={NotFound} />
                        <Route path="/login" component={Login} />
                        <Route path="/home" render={()=>{
                            return  this.hasLogin()? <Home /> : <h1>尚未登录</h1>
                        }} />
                        <Route path="/product/list" component={Empty} />
                        <Route path="/product/edit" component={Empty} />
                        <Route path="/product/supplier" component={Empty} />
                        <Route path="/product/banner" component={Empty} />
                        <Route path="/product/recommend" component={Empty} />
                        <Route path="/product/video" component={ProductVideo} />
                        <Route path="/purchase/list" component={Empty} />
                        <Route path="/purchase/edit" component={Empty} />
                        <Route path="/receiving/list" component={Empty} />
                        <Route path="/receiving/edit" component={Empty} />
                        <Route path="/order/list" component={Empty} />
                        <Route path="/user/list" component={UserList} />
                        <Route path="/user/edit" component={UserEdit} />
                        <Route path="/user/role" component={Empty} />
                        <Route path="/user/address" component={Empty} />
                        <Route path="/user/discoun" component={Empty} />
                        <Redirect path="/" to="/login" exact/>
                        <Redirect to="/404" />
                    </Switch>
                </Layout>
            </Router>
            
        )
    }
}
export default  App